<!--Author: W3layouts
Author URL: http://w3layouts.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/-->
<!DOCTYPE html>
<html lang="en">
<head>

<title>免费注册</title>
<!-- custom-theme -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Pet Adoption Form  Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template, Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);
		function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- //custom-theme -->
	<script src="../js/jquery-1.11.0.min.js"></script>
<link href="../css/style1.css" rel="stylesheet" type="text/css" media="all" />
<link href="//fonts.googleapis.com/css?family=Muli:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i&amp;subset=latin-ext,vietnamese" rel="stylesheet">
<link href="//fonts.googleapis.com/css?family=Dosis:200,300,400,500,600,700,800&amp;subset=latin-ext" rel="stylesheet">
</head>
<script>

		function unameyz() {
			var username = $("#username").val();
			if(username==""||username==null){
				$("#uname").text("用户名不能为空!");
				return;
			}else{
				$("#uname").text("");
			}
		}
		function upwdyz() {
			var password = $("#password").val();
			if(password==""||password==null){
				$("#upwd").text("密码不能为空!");
				return;
			}else{
				$("#upwd").text("");
			}
		}
		function uphoneyz() {
			var phone = $("#phone").val();
			if(phone==''||phone==null){
				$("#uphone").text("手机号不能为空!");
				return;
			}else if(!(/^1[3456789]\d{9}$/.test(phone))){
				$("#uphone").text("手机号格式错误!");
				return;
			}else{
				$("#uphone").text("");
			}
			$.ajax({
				url:'yz/'+phone,
				success:function (result) {
					if(result>0){
						$("#uphone").text("该手机号已注册!");
					}else{
						$("#uphone").text("");
					}
				}
			})
		}
		function register() {
			var flag = $("#pho").html();
			if(flag=="手机号格式错误!"||flag=="手机号不能为空!"||flag=="该手机号已注册!"){
				return;
			}
			var username = $("#username").val();
			var password = $("#password").val();
			if(username==""||username==null||password==""||password==null){
				alert("请正确填写相关信息...");
				return;
			}
			var phone = $("#phone").val();
			$.ajax({
				url:'users/register',
				data:{"username":username,"password":password,"phone":phone},
				success:function (result) {
					if(result>0){
						alert("注册成功!");
						window.location.href="login.html";
					}else{
						alert("注册失败!");
					}
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					alert(XMLHttpRequest.status);
					alert(XMLHttpRequest.readyState);
					alert(textStatus);
				}
			})
		}





</script>
<body class="agileits_w3layouts">
    <h1 class="agile_head text-center" style="padding-left: 430px">铛铛宠物店</h1>
    <div class="w3layouts_main wrap">
	  <h2>免费注册</h2>
	    <form class="agile_form">
			<div class="icon1 w3ls-name1">
				<label>用户名<span id="uname" style="color:red"></span></label>
				<input  placeholder=" " id="username" name="username" type="text" required="" onblur="unameyz()">
			</div>
			<div class="icon1 icon2">
				<label>密码<span id="upwd" style="color:red"></span></label>
				<input  placeholder=" " id="password" name="password" type="password" required="" onblur="upwdyz()">
			</div>
			<div class="clear"></div>
			<div class="icon1 icon3">
				<label>手机号<span id="uphone" style="color: red"></span></label>
				<input placeholder=" " id="phone" name="phone" type="text" onblur="uphoneyz()" required="">
			</div>
			<input name="sub" value="submit" type="button" onclick="register()"/>
		</form>
	</div>
	<div class="clear"></div>
</body>
</html>